//
//  AppFuncs.m
//  YLCommon
//
//  Created by Apple on 2017/9/26.
//  Copyright © 2017年 Apple. All rights reserved.
//

#import "AppFuncs.h"

//是否是纯数字
BOOL isNumText(NSString *text){
    NSString * regex  = @"[0-9]*";
    NSPredicate * pred  = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    BOOL isMatch   = [pred evaluateWithObject:text];
    if (isMatch) {
        return YES;
    }else{
        return NO;
    }
}

BOOL isValidatePhone(NSString *phone,NSString *phoneRegex){
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
    return [phoneTest evaluateWithObject:phone];
}

BOOL isValidateMobile(NSString *mobile){
    //手机号以13， 15，18开头，八个 \d 数字字符
    NSString *phoneRegex = @"^((13[0-9])|(10[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
    return [phoneTest evaluateWithObject:mobile];
}

 //检测邀请码
BOOL isCheckInvateCode(NSString *code)
{
    NSString * regex = @"^[A-Za-z0-9]+$";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    BOOL isMatch = [pred evaluateWithObject:code];
    return isMatch;
}

BOOL isContainChinese(NSString *targetSring)
{
    BOOL result = NO;
    for (NSInteger i = 0; i < targetSring.length; i++)
    {
        unichar  a = [targetSring characterAtIndex:i];
        if(a > 0x4E00 && a < 0x9FA5)
        {
            result = YES;
            break;
        }
    }
    return result;
}

UIColor *getRandColor(){
    return getColor(arc4random()%255, arc4random()%255, arc4random()%255, 255);
}

UIColor *getPureColor(int r, int a ){
    return getColor(r, r, r, a);
}
UIColor *getColor(int r, int g, int b, int a){
    return [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a/255.0];
}


CGFloat getScreenWidth(){
    UIScreen *screen = [UIScreen mainScreen];
    return screen.bounds.size.width;
}
CGFloat getScreenHeight(){
    UIScreen *screen = [UIScreen mainScreen];
    return screen.bounds.size.height;
}
CGFloat get6sConstantWidth()
{
    return 375;
}
CGFloat get6sConstantHeight()
{
    return 667;
}
CGFloat get6sConstantWidthScale()
{
    return getScreenWidth()/get6sConstantWidth();
}
CGFloat get6sConstantHeightScale()
{
    return getScreenHeight()/get6sConstantHeight();
}


#pragma mark - UI
UIView *getDefaultSeparationLine(void)
{
    UIView *line = [UIView new];
    line.backgroundColor = ZBColorChangeRGB(0xf2f2f2, 1.0);
    return line;
}
UIImageView *getDefaultContentAspectFillImgView(void)
{
    UIImageView *imgView = [UIImageView new];
    imgView.contentMode = UIViewContentModeScaleAspectFill;
    imgView.clipsToBounds = YES;
    return imgView;
}

UILabel *getDefaultLabel(UIFont *font, UIColor *color)
{
    UILabel *label = [UILabel new];
    label.font = font;
    label.textColor = color;
    return label;
}



//获取默认的Button
UIButton *getDefaultButton(UIFont *font, UIColor *normalColor,UIColor *selectColor)
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    if(font != nil)
    button.titleLabel.font = font;
    
    if(normalColor != nil)
    [button setTitleColor:normalColor forState:UIControlStateNormal];
    
    if(selectColor != nil)
    [button setTitleColor:selectColor forState:UIControlStateSelected];
    return button;
}
